/*********************************************************
 * File:PortalApp.java
 * 
 * Version 1.0
 * 
 * Date     2004-2-21
 * Author   HuangYong
 * 
 * Copyright (C) 2003 VandaGroup.
 * all rights reserved.
 * 
 ********************************************************/

package com.vandagroup.portal;

import java.sql.SQLException;

import com.vandagroup.common.bean.BaseBean;
import com.vandagroup.common.po.PortalPO;
import com.vandagroup.common.util.SQLFormat;

/**
 * @author HuangYong 说明：
 */
public class PortalApp {

	public static String getPaentFuncID(String[][] roles, String orgID)
			throws SQLException, Exception {
		StringBuffer rtn = new StringBuffer();
		if (roles != null && roles.length != 0) {
			String[] roleIDs = new String[roles.length];
			for (int i = 0; i < roles.length; i++) {
				roleIDs[i] = roles[i][0];
			}
			PortalPO po = new PortalPO();
			String t1 = po
					.queryKey("select roleid from orgrole where orgid<>'00000000' and  type='1' and roleid in("
							+ SQLFormat.joinAsList(roleIDs, true) + ")");
			String t2 = po
					.queryKey("select roleid from orgrole where orgid='00000000' and  type='1' and roleid in("
							+ SQLFormat.joinAsList(roleIDs, true) + ")");
			String sql = "SELECT LEVELID FROM FUNC WHERE FUNCID IN (SELECT FUNCID FROM ORGROLEFUNC WHERE ORGID = '"
					+ orgID
					+ "' AND ROLEID IN ("
					+ t1
					+ ") or orgid='00000000' and roleid in( " + t2 + "))";
			// String sql = "SELECT distinct LEVELID FROM ORGROLEFUNC";

			// System.out.println("sql:"+sql);
			BaseBean[] baseBeans = po.query(sql);
			if (baseBeans != null && baseBeans.length != 0) {
				for (int i = 0; i < baseBeans.length; i++) {
					String levelID = ((String) (baseBeans[i].get("LEVELID")))
							.trim();
					for (int j = 0; levelID.length() % 3 == 0
							&& j < levelID.length() / 3; j++) {
						String temp = levelID.substring(0, (j * 3 + 3));
						rtn.append("'" + temp + "',");
					}
				}
			}
		} else {
			rtn.append("'',");
		}
		if (rtn.length() > 0) {
			rtn.setLength(rtn.length() - 1);
		}
		return rtn.toString();
	}
}
